package com.perfma.xtest.byd;

import java.io.File;

public class FileExtensionConverter {
    public static void main(String[] args) {
        String folderPath = "/Users/sijunhui/Downloads/tar/mqtt-xmeter-2.0.2-jar"; // 替换为你的文件夹路径
        convertFileExtension(folderPath);
    }

    public static void convertFileExtension(String folderPath) {
        File folder = new File(folderPath);
        convertFileExtensionRecursive(folder);
    }

    public static void convertFileExtensionRecursive(File folder) {
        File[] files = folder.listFiles();

        for (File file : files) {
            if (file.isFile()) {
                String fileName = file.getName();
                String filePath = file.getAbsolutePath();
                int dotIndex = fileName.lastIndexOf(".");

                if (dotIndex != -1) {
                    String fileExtension = fileName.substring(dotIndex);

                    if (fileExtension.equals(".class")) {
                        String newFileName = fileName.substring(0, dotIndex) + ".java";
                        String newFilePath = filePath.substring(0, filePath.lastIndexOf(File.separator) + 1) + newFileName;

                        File newFile = new File(newFilePath);
                        file.renameTo(newFile);

                        System.out.println("Converted: " + fileName + " -> " + newFileName);
                    }
                }
            } else if (file.isDirectory()) {
                convertFileExtensionRecursive(file);
            }
        }
    }
}
